#include<iostream>
#include<signal.h>
#include<unistd.h>

using namespace std;

void print(sigset_t &pending)
{
    cout<<"pending 表打印中...."<<endl;
    for(int sig=31;sig>=0;sig--)
    {
        if(sigismember(&pending,sig))
        {
            cout<<"1";
        }
        else
        {
            cout<<"0";
        }
    }
    cout<<endl;
}
void handler(int signo)
{
    cout<<"signal: "<<signo<<endl;
    sigset_t pending;
    sigemptyset(&pending);
    while(true)
    {
        sigpending(&pending);
        print(pending);
    }
}

int main()
{
    struct sigaction act,oldact;
    act.sa_handler=handler;
    act.sa_flags=0;

    sigemptyset(&act.sa_mask);
    sigaction(2,&act,&oldact);
    
    while(true) sleep(1);
    return 0;
}